#include "StdAfx.h"
#include "alway_regex.h"
#include <regex>
using namespace std::tr1;

alway_regex::alway_regex(void)
{
}

alway_regex::~alway_regex(void)
{
}

void alway_regex::parse(const wchar_t* filename)
{
	wifstream infile;
	infile.open(filename,ios::in);
	if( !infile.is_open())
		return ;


	istreambuf_iterator<wchar_t> begin(infile),end;
	wstring text(begin,end);


 	const wregex rex(L"id\\s+[0-9]+\\.(.*)\\s*\\{\\s+source\\s+text\\s*=\\s*\"(.*)\";\\s*\\s+regex\\s+text\\s*=\\s*\"(.*)\";\\s*\\s+replace\\s+text\\s*=\\s*\"(.*)\";\\s*\\};");


	wstring::const_iterator text_beg = text.begin();
	wstring::const_iterator text_end = text.end();
	wsmatch rmatch;
	while( regex_search(text_beg,text_end,rmatch,rex))
	{
		room lroom;
		if( rmatch.size() == 5)
		{
			lroom.name = rmatch[1].str();
			lroom.source_text = rmatch[2].str();
			lroom.regex_text = rmatch[3].str();
			lroom.replace_text = rmatch[4].str();
			rooms.push_back(lroom);
		}
		text_beg = rmatch[0].second;
	}



}

